import { createRouter, createWebHashHistory } from "vue-router";
import { staticRouters } from "./modules/staticRouter";
import { errors } from "./modules/error";

/** 创建路由实例 */
/** @type {import("vue-router").Router} */
export const router = createRouter({
  history: createWebHashHistory(),
  routes: [...staticRouters, ...errors],
  strict: true,
  scrollBehavior(to, from, savedPosition) {
    return new Promise(resolve => {
      if (savedPosition) {
        return savedPosition;
      } else {
        if (from.meta.saveScrollTop) {
          const top: number =
            document.documentElement.scrollTop || document.body.scrollTop;
          resolve({ left: 0, top });
        }
      }
    });
  }
});

export default router;
